# -*- coding: utf-8 -*-

'''eof
name:申请人是否为法定代表人
code:R01_EG_CorporationChangeAndNotShareholder_WHB
tableName:
columnName:
groups:强规则>工商信息校验
dependencies:EG_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''

import sys
import pandas as pd
import json
from datetime import datetime


reload(sys)
sys.setdefaultencoding('utf-8')


def FormatData(tableName):
    try:
        eg = EG_DSJ.get("data").get("R1103V3")[0].get(tableName)
        return eg if isinstance(eg, list) else [{}]
    except:
        return [{}]


def getRule01():
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    basic_list = FormatData("basicList")

    try:
        frname = basic_list[0].get("frName").strip()
        legalPerson = ratingRequest.get("legalPerson").strip()

        if frname in null_type_list:
            raise RuntimeError("法人名称为空")
        if legalPerson in null_type_list:
            raise RuntimeError("传入数据法人名称为空")
    except:
        raise RuntimeError("法人名称为空")

    if legalPerson != frname:
        return 0
    else:
        return 1

    # if shareHolderList == [{}]:
    #     return u'缺失值'
    # else:
    #     shareholderNameList = []
    #     if len(shareHolderList) >= 1:
    #         for i in shareHolderList:
    #             shareholderName = i.get("shareholderName")
    #             shareholderNameList.append(shareholderName)
    #     if legalPerson != frname and legalPerson not in shareholderNameList:
    #         return 0
    #     else:
    #         return 1


if __name__ == "__main__":
    ratingRequest = {"legalPerson": u"朱为广", "legalPersonIdCard": "510102196706108511"}
    file_obj = open(r'../data/WHB/R01_EG_CorporationChangeAndNotShareholder_WHB/EG_DSJ.json', 'r')
    content = file_obj.read()
    EG_DSJ = json.loads(content, strict=False)
    aa = getRule01()
    print aa

result = getRule01()
